package com.seecoder.BlueWhale.vo;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.xmlbeans.impl.common.NameUtil;

import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class PageVO<T> {
    int currentPage;
    int totalPages;
    List<T> content;

    public PageVO(List<T> total, int page, int pageSz) {
        int totalSz = total.size();
        int startI = (page - 1) * pageSz;
        int endI = page * pageSz;
        currentPage = page;
        totalPages = (totalSz + pageSz - 1) / pageSz;
        if (startI > totalSz) {
            content = null;
            return;
        }
        if (endI > totalSz) {
            endI = totalSz;
        }
        content = total.subList(startI, endI);
    }

}